<?php
    class quycachdb
    {
        public $_tablename = "giaphucvn_quycach";
        public function getList($MaQuyCach = 0, $TenQuyCach = '', $order = '', $start = 0, $num = 30, $all = 0)
		{
			$sql = "SELECT * FROM ".$this->_tablename." WHERE (1)";
			
			if ($MaQuyCach != 0)
				$sql .= " AND MaQuyCach = " . dataservice::QuoteSmart($MaQuyCach);
			
			if ($TenQuyCach != '')
				$sql .= " AND TenQuyCach LIKE " . dataservice::QuoteSmart('%' . $TenQuyCach . '%');
			
			if ($order != '')
				$sql .= " ORDER BY " . $order . " DESC";
			
			if($all == 0)
				$sql .= " LIMIT " . $start . ", ".$num;
			//echo $sql;
			$db = new dataservice();
			$ret = $db->ExecuteQuery($sql);
			return $ret;
		}
        
        public function add($TenQuyCach = '')
		{
			$sql = "INSERT INTO ".$this->_tablename."(TenQuyCach) VALUES(" . dataservice::QuoteSmart($TenQuyCach) . ")";
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function update($MaQuyCach = 0, $TenQuyCach = '')
		{
			$sql = "UPDATE ".$this->_tablename." SET TenQuyCach = " . dataservice::QuoteSmart($TenQuyCach) . " WHERE MaQuyCach = ".dataservice::QuoteSmart($MaQuyCach);
			//echo $sql;
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function delete($MaQuyCach = 0)
		{
			$sql = "DELETE FROM ".$this->_tablename." WHERE (1)";
			
			if ($MaQuyCach != 0)
				$sql .= " AND MaQuyCach = " . dataservice::QuoteSmart($MaQuyCach);
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
        
        public function issetTypes($MaQuyCach = 0, $TenQuyCach = "")
		{
			$sql = "SELECT COUNT(*) AS SoDong FROM ".$this->_tablename." WHERE (1)";
            
            if($MaQuyCach != 0)
				$sql .= " AND MaQuyCach = $MaQuyCach";
            
			if($TenQuyCach != "")
				$sql .= " OR TenQuyCach = '$TenQuyCach'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
        
        public function issetType($TenQuyCach = "")
		{
			$sql = "SELECT COUNT(*) AS SoDong FROM ".$this->_tablename." WHERE (1)";
			if($TenQuyCach != "")
				$sql .= " AND TenQuyCach = '$TenQuyCach'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
    }
?>